define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Shopinfo, $stateParams, GoDialog, GoShare,GoWapAuth, $ionicModal) {
		
		$scope.store_id = $stateParams.store_id;
		
		//初始化
		$scope.init_data = function() {
			Shopinfo.shop_info($scope.store_id, function(data) {
				$scope.info = data;
				$scope.go_share_wx();
			})
		}
		$scope.init_data();
		
		//收藏店铺
//		$scope.add_store = function() {
//			Shopinfo.add_store($scope.store_id, function(data) {
//				if(data.success == true) {
//					GoDialog.toast("收藏成功");
//				} else {
//					GoDialog.toast(data.msg);
//				}
//			})
//		}
		
		/***************分享**************/
		$ionicModal.fromTemplateUrl("templates/modal/keyshare_modal.html", {
			scope: $scope,
			animation: "slide-in-up"
		}).then(function(modal) {
			$scope.modal_share = modal;
		});
		//打开
		$scope.openModal_share = function() {
			if($scope.openGuidShare()) {
				$scope.modal_share.show();
			}
		}
		//隐藏
		$scope.closeModal_share = function() {
			$scope.modal_share.hide();
		}
		/***************分享**************/
		
		
		//分享（自定义每个页面的参数）
		$scope.go_share = function(index) {
			var param = new Object();
			if($scope.info) {
				param.title = $scope.info.store_name ? $scope.info.comp_name : undefined;
				param.desc = $scope.info.brief ? $scope.info.brief : undefined;
				param.thumb = $scope.info.logo ? $scope.info.logo : undefined;
				param.link = 'shopinfo/' + $scope.info.store_id;
			}
			GoShare.do_share(param, index);
		}
		
		//分享（自定义每个页面的参数）
		$scope.go_share_wx = function() {
			//分享打开
			GoWapAuth.execisoff(false);
			//设置分享
			var param = new Object();
			if($scope.info){
				param.title = $scope.info.store_name ? $scope.info.comp_name : undefined;
				param.desc = $scope.info.brief ? $scope.info.brief : undefined;
				param.thumb = $scope.info.logo ? $scope.info.logo : undefined;
				param.link = 'shopinfo/' + $scope.info.store_id;
			}
			GoWapAuth.execshare(param);
		}
		
		
	}

	controller.$inject = ['$scope', 'Shopinfo', '$stateParams', 'GoDialog','GoShare','GoWapAuth','$ionicModal'];

	return app.registerController("shopinfoctrl",controller);
});